//
//  BaseViewController.m
//  IconMaster
//
//  Created by mac on 2017/7/25.
//  Copyright © 2017年 yangweiwei. All rights reserved.
//

#import "BaseViewController.h"
#import "CImageUtil.h"
#import "CIconView.h"
#import "MongooseDaemon.h"
#import "RMStepsController.h"

@interface BaseViewController ()
@property (nonatomic, strong) NSDictionary *inputDict;
@end

@implementation BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}
- (void)setImageViewINNav{

    UIImageView *navImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, KWidth, 64)];
    navImage.image = [UIImage imageNamed:@"navall"];
    [self.view addSubview:navImage];
    [navImage sendSubviewToBack:self.view];
}
- (void)setBarType{
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.translucent = YES;
    UIColor *color = [UIColor clearColor];
    CGRect rect = CGRectMake(0.0f, 0.0f, KWidth, 64);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.clipsToBounds = YES;
    self.navigationController.navigationBar.titleTextAttributes=@{NSForegroundColorAttributeName:[UIColor whiteColor]};
     
  
}
- (void)creatIconWithMessage:(NSDictionary *)dict{

//    self.inputDict = @{@"iconImage":image2,
//                       @"title":@"大姐",
//                       //                       @"iconView":image1,
//                       @"value":@"https://itunes.apple.com/us/app/qq/id444934666?mt=8"};
    self.inputDict = dict;
    UIImage* iconImage = [self.inputDict objectForKey:@"iconImage"];
    SaveImageToDocument(iconImage, @"the_icon.png");
    NSString* title = [self.inputDict objectForKey:@"title"];
    NSString* value = [self.inputDict objectForKey:@"value"];
    
    [MongooseDaemon instance].composedUrl.title = title;
    [MongooseDaemon instance].composedUrl.password = nil;
    [MongooseDaemon instance].composedUrl.realUrl = value;
    
    NSString* urlString = [NSString stringWithFormat:@"http://localhost:8080/wei%ld",time(NULL)];
//    NSLog(@"%@",urlString);
//    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{}   completionHandler:^(BOOL success) {
            if (success) {
                NSLog(@"Opened url");
            }
        }];
    [self.stepsController finishedAllSteps];

}

-(void)alterAction:(NSString *)promptString{
    
    //初始化提示框；
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"温馨提示", nil)  message:promptString preferredStyle:  UIAlertControllerStyleAlert];
    
    [alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"确定", nil)  style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        //点击按钮的响应事件；
    }]];
    
    //弹出提示框；@"输入的推荐人号码错误"
    [self presentViewController:alert animated:true completion:nil];
}
- (void)showAdmobInController:(UIViewController*)controller {
    [AdAndHint showInterstitialViewInController:controller
                               withRatioPercent:40];
}
- (void)checkIOSInStore:(isbool)isbool{
    
    [IconmasterHttp GreatNetWorkingRequestType:GreatRequestType_GET andurl:CheckIOSINstore andparameters:nil andcomplete:^(id json, NSError *error) {
        if ([json[@"code"] integerValue] == 200) {
            isbool([json[@"data"][@"inStore"] integerValue]);
        }
        
    }];
}
- (void)shareDictInfo:(shareDict)shareDict{
    [IconmasterHttp GreatNetWorkingRequestType:GreatRequestType_GET andurl:ShareInfoURL andparameters:nil andcomplete:^(id json, NSError *error) {
        if ([json[@"code"] integerValue] == 200) {
            shareDict(json[@"data"][@"shareinfo"]);
        }
    }];
    
}
-(void)writefile:(NSDictionary *)string fileName:(NSString *)fileName
{
    //    NSLog(@"fileName==%@",fileName);
    NSArray *paths  = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
    NSString *homePath = [paths objectAtIndex:0];
    
    NSString *filePath = [homePath stringByAppendingPathComponent:fileName];
    
    NSFileManager *fileManager = [NSFileManager defaultManager];
    
    if(![fileManager fileExistsAtPath:filePath]) //如果不存在
    {
        //        NSLog(@"-------文件不存在，写入文件----------");
        NSError *error;
        //        [string writeToFile:fileName atomically:YES];
        if([string writeToFile:fileName atomically:YES])
        {
            //            NSLog(@"------写入文件------success");
        }
        else
        {
            //            NSLog(@"------写入文件------fail,error==%@",error);
        }
    }
    else//追加写入文件，而不是覆盖原来的文件
    {
        
        NSError *error;
        if([string writeToFile:fileName atomically:YES])
        {
            //            NSLog(@"------写入文件------success");
        }
        else
        {
            //            NSLog(@"------写入文件------fail,error==%@",error);
        }
 
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
